package com.javalab._7thread._2Operate._1Sleep;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 演示线程睡眠
 * 睡眠会让当前线程暂停一段时间之后继续执行
 * sleep期间会一直持有锁，不释放
 */
public class SleepThread implements Runnable {
    private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    @Override
    public void run() {
        try {
            System.out.println("begin sleep " + SIMPLE_DATE_FORMAT.format(new Date()));
            Thread.sleep(1000L);
            System.out.println("stop sleep " + SIMPLE_DATE_FORMAT.format(new Date()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
